package com.payment.web.controller.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.payment.common.base.AjaxResult;
import com.payment.common.utils.RedisPoolUtil;
import com.payment.system.domain.SystemConfig;
import com.payment.system.service.ICardEvaluateService;
import com.payment.system.service.ISystemConfigService;

/**
 * @author fuzhili
 * @Description: app 卡测评
 * @date 2019/11/22 10:30
 */
@Controller
@RequestMapping("/app/cardEvaluate")
public class CardEvaluateController {
    @Autowired
    private ICardEvaluateService cardEvaluateService;
    @Autowired
    private ISystemConfigService configService;

    
    
	/**
	 * 获取金额 
	 * @return
	 */
	@PostMapping("/getMoney")
	@ResponseBody
	public AjaxResult getMoney() {
		String activityUpgrade = "";
		try {
			activityUpgrade = RedisPoolUtil.get("activityUpgrade");
		} catch (Exception e) {
			activityUpgrade = "nil";
		}
		if (activityUpgrade == null || "nil".equals(activityUpgrade) || "".equals(activityUpgrade)) {
			SystemConfig config = configService.selectSystemConfigByConfigCode("activityUpgrade");
			RedisPoolUtil.setex("activityUpgrade", config.getConfigValue(), 86400);
			activityUpgrade = config.getConfigValue();
		}
		JSONObject upgradeJson = JSONObject.parseObject(activityUpgrade);
		return AjaxResult.successAndData("成功", upgradeJson.getBigDecimal("cardEvaluate"));
	}
    
    /**
     * 发送验证码
     * @param merId 用户id
     * @param bankCardNo 卡号
     * @param name  名称
     * @param userIdCard 身份证号
     * @param bankCardPhone 手机号
     * @return
     */
    @PostMapping("/sendSms")
    @ResponseBody
    public AjaxResult sendSms(String merId, String bankCardNo, String name, String userIdCard, String bankCardPhone) {
        return cardEvaluateService.sendSms(merId, bankCardNo, name, userIdCard, bankCardPhone);
    }

    /**
     * 确认验证码
     * @param seriaNo 订单号
     * @param identifyingCode 验证码
     * @param serialNumber  序列号
     * @return
     */
    @PostMapping("/smsConfirm")
    @ResponseBody
    public AjaxResult smsConfirm(String seriaNo, String identifyingCode, String serialNumber) {
        return cardEvaluateService.smsConfirm(seriaNo, identifyingCode, serialNumber);
    }

	/**
	 * 下单 返回H5卡测评链接
	 * 
	 * @param orderId
	 *            订单id
	 * @param bankCardNo
	 *            卡号
	 * @param name
	 *            名称
	 * @param userIdCard
	 *            身份证
	 * @param bankCardPhone
	 *            手机号
	 * @param identifyingCode
	 *            验证码
	 * @param serialNumber
	 *            序列号
	 * @return
	 */
	@PostMapping("/placeOrder")
	@ResponseBody
	public AjaxResult placeOrder(String orderId, String bankCardNo, String name, String userIdCard,
			String bankCardPhone, String identifyingCode, String serialNumber) {
		return cardEvaluateService.placeOrder(orderId, bankCardNo, name, userIdCard, bankCardPhone, identifyingCode,
				serialNumber);
	}
	
	@PostMapping("/getHistoryList")
	@ResponseBody
	public AjaxResult getHistoryList(String merId,Integer page) {
		return cardEvaluateService.getHistoryList(merId,page);
	}
	
}
